<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%String path = request.getContextPath() ;%>
<%@ taglib uri="/WEB-INF/tld/c.tld" prefix="c" %> 
<%@ taglib uri="/WEB-INF/tld/ui.tld" prefix="ui" %> 
<%@ taglib uri="/WEB-INF/tld/sys.tld" prefix="sys" %>
<!DOCTYPE html>
<html lang="zh-CN" >
<head>
<c:set var="ctx" value="${pageContext.request.contextPath}" />
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>垫款单列表</title>
<jsp:include page="../../import.jsp" flush="true" />
</head>
<script type="text/javascript">
	var grid = null;
	var _mfrId;
	var pageInApp={}; // to 下一级子窗口 接口
    var pageInTab=null;
	$(function () {
		initTab();
        _mfrId = '${mfrId}';
        var _url = '<%=path%>/dk/dkbillinfo/initList.do?';
	    $("#ligergrid1").ligerGrid({
	    	url: _url,
	    	method : 'get',
	        columns: [
                { display: '垫款规则名称', align:'left', width: 200,
                    render: function (rowdata, rowindex, value){
                        return rowdata.ruleNm;
                    }
                },
	            { display: '垫款单名称', align:'left', width: 200,
	            	render: function (rowdata, rowindex, value){
	                	return rowdata.billNm;
	            	}	
	            },
                { display: '再融资项目名称', align:'left', width: 200,
                    render: function (rowdata, rowindex, value){
                        return rowdata.refPrjNm;
                    }
                },
                { display: '垫款类型', width: 80,name: 'dkStyleCd',
                    render: function (rowdata, rowindex, value){
                        var dkStyleCd = rowdata.dkStyleCd;
                        if(StringUtils.isNotEmpty(dkStyleCd)){
                            if(dkStyleCd == '1'){
                                return '明垫';
                            }else if(dkStyleCd == '0'){
                                return '暗垫';
                            }
                        }
                    }
                },
                { display:'生成时间',name : 'crtTm', align:'left', width: 100,
                    render: function (rowdata, rowindex, value){
                        return renderDate2(rowdata, rowindex, value)
                    }
                },
	            { display: '状态', width: 80,name: 'billStsCd',
	            	render: function (rowdata, rowindex, value){
							var billStsCd = rowdata.billStsCd;
							if(StringUtils.isNotEmpty(billStsCd)){
								if(billStsCd == '1'){
									return '垫款中';
								}else if(billStsCd == '0'){
									return '结束';
								}
							}
	            	}
	            },
	            { display: '操作', width: 200 , align:'left',
	            	render: function (rowdata, rowindex, value){
                        if(rowdata.billStsCd == "0"){
                            var zx ='<span style="color:#AAAAAA;" class="sq-button-hasicon"><i class="sqBtnIco_4"></i>修改</span>';
                        }else{
                            if(rowdata.dkStyleCd=="0"){ //暗垫
                                var zx='<a class="sq-button-hasicon" href="javascript:toDkBillDtlZx(';
                                zx+="'"+rowdata.id+"'";
                                zx+=')"><i class="sqBtnIco_1"></i>修改</a>';
                            }else{ //
                                var zx='<a class="sq-button-hasicon" href="javascript:toModify(';
                                zx+="'"+rowdata.id+"'";
                                zx+=')"><i class="sqBtnIco_1"></i>修改</a>';
                            }

                        }
                        if(rowdata.billStsCd == "0"){
                            var js ='<span style="color:#AAAAAA;" class="sq-button-hasicon"><i class="sqBtnIco_4"></i>结束</span>';
                        }else{
                            var js='<a class="sq-button-hasicon" href="javascript:updateRecord(';
                            js+="'"+rowdata.id+"'";
                            js+=')"><i class="sqBtnIco_1"></i>结束</a>';
                        }
                        var xq='<a class="sq-button-hasicon" href="javascript:showDetail(';
                        xq+="'"+rowdata.id+"'";
                        xq+=')"><i class="sqBtnIco_1"></i>详情</a>';
                        var end = "";
                        if(rowdata.dkStyleCd=="1"){ //暗垫
                            xq='<a class="sq-button-hasicon" href="javascript:showMingDianDetail(';
                            xq+="'"+rowdata.id+"'";
                            xq+=')"><i class="sqBtnIco_1"></i>详情</a>';
                        }

                        return end + zx + js + xq;
	            	}
	            }
	        ],
	        pageSize:10,
	        root:'rows',
	        record:'total',
	        hideLoadButton : true,
	        width: '100%',
	        height:'100%',
	        heightDiff:-2,
	        checkbox:true,
	        fixedCellHeight: false,
	        rownumbers:true,
//			onAfterShowData: getFlowIds,
	    });
	    grid = liger.get("ligergrid1");
	    grid.setHeight(100);
	    $("#searchBar").ligerForm();
	
	    $("#searchBtn").click(function(event) {
	         var form = new liger.get("searchBar");
	         var data = form.getData();
	         console.log(JSON.stringify(data));
	         for (name in data){
	            grid.setParm(name,data[name]);
	         };
	        grid.reload();
	    });
	    $("#clearBtn").click(function(event) {
	        $("#resetBtn").click();  //重置 input-text
	        var form = liger.get("searchBar");
	        form.setData({  //重置select等特殊表单
	            "billNm": " ",
	            "refPrjNm": " ",
                "billStsCd": " "
	        });
	    });
	});

	 //回调
	var callback = function () {
		grid.reload();
    };
	//审核
	function changeAudStsCd(_id,_splAttrCd){
		if(StringUtils.isEmpty(_id)) return;
		Add_navTab('PrdSpl_Aud'+_id,'审核垫款单信息','<%=path%>/product/splInfo/toAddPage.do?isShowAuditBtn=1&id='+_id+'&splAttrCd='+_splAttrCd, callback);
	}

    //结束按钮
    function updateRecord(_id){
        if(!_id)return;
        /*var _ids = [];
        _ids.push(_id);*/
        $.ligerDialog.confirm('确定结束吗?', function (flag) {
            if(flag == false)return;
            var wait_dialog;
            $.ajax({
                type: 'post',
                dataType:'json',
                //data:{ids:JSON.stringify(_ids)},
                data:{id:_id},
                url: '<%=path%>/dk/dkbillinfo/modify.do',
                beforeSend: function(){
                    wait_dialog=$.ligerDialog.SQalert({content: LogUtils.LOG_CMM_DATA_LOADING ,SQ_type: "waitting" });
                },
                success:function(msg){
                    wait_dialog.close();
                    if(msg.success == 1){
                        $.ligerDialog.SQalert({content:msg.info, SQ_type: "success"});
                        grid.reload();
                    }else{
                        $.ligerDialog.SQalert({content:msg.info, SQ_type: "error"});
                    }
                }
            });
        });
    }

    /**
     * 明垫
     */
    function toModify(_id){
	    Add_navTab("DkBillDtl_1"+_id ,'垫款单执行','<%=path%>/dk/dkbilldtl/toModifyPage.do?billId='+_id);
    }
    function showMingDianDetail(_id){
        Add_navTab("DkBillDtl_2"+_id ,'垫款单执行','<%=path%>/dk/dkbilldtl/toModifyPage.do?viewFlag=1&billId='+_id);
    }

	//到垫款单执行页面
	function toDkBillDtlZx(_id,billStsCd){
		if(!_id)return;
		/*if(billStsCd==0){
            $.ligerDialog.SQalert({content:"结束状态不可执行！", SQ_type: "success"});
            return;
        }*/
		if(_mfrId==""){
			parent.mainApp.f_addTab('DkBillDtl_1'+_id,'垫款单执行','<%=path%>/dk/dkbilldtl/toDkBillDtlZx.do?billId='+_id);
		}else{
			parent.parent.mainApp.f_addTab('DkBillDtl_1'+_id,'垫款单执行','<%=path%>/dk/dkbilldtl/toDkBillDtlZx.do?billId='+_id);
		}
	}
	
	//详情
	function showDetail(_id){
		if(!_id)return;
		if(_mfrId==""){
			parent.mainApp.f_addTab('DkBillDtlDetail_1'+_id,'垫款单详情','<%=path%>/dk/dkbilldtl/toDkBillDtlDetail.do?billId='+_id);
		}else{
			parent.parent.mainApp.f_addTab('DkBillDtlDetail_1'+_id,'垫款单详情','<%=path%>/dk/dkbilldtl/toDkBillDtlDetail.do?billId='+_id);
		}
	}
	
	function iframeResize () {
	    if (parent.mainApp) {
	        parent.mainApp.parentTab.onResize();
	    };
	}
    //格式化时间
    function renderDate2(rowdata, index, value) {
        var dateStr = "";
        if (null != value) {
            var date = new Date(value);
            //dateStr = DateUtils.formatDate(date, "yyyy-MM-dd hh:mm");
            dateStr = DateUtils.formatDate(date, "yyyy-MM-dd");
        }
        return dateStr;
    }
	
	var loadedTabs = [];
	//初始化Tab页签
	function initTab(){
		pageInTab = $("#pageInTab").ligerTab({
			height: 'auto',
			contextmenu: false,
			minIframeHeight: GET_minIframeHeight(),
			onBeforeSelectTabItem: function(tabid) {
				var selectedRows = grid.getSelectedRows();
				if(tabid!="tabA"){
					if (selectedRows.length != 1) {
			             $.ligerDialog.SQalert({content: LogUtils.LOG_CMM_SELECT_ONLY_A_ROW, SQ_type: "warning"});
			             return false;
			         }
				}
			},
			onAfterSelectTabItem: function(tabid) {
				var selectedRows = grid.getSelectedRows();
				if(tabid!="tabA"){
					if (selectedRows.length != 1) {
			             $.ligerDialog.SQalert({content: LogUtils.LOG_CMM_SELECT_ONLY_A_ROW, SQ_type: "warning"});
			             return false;
			         }else{
							if (loadedTabs.indexOf(selectedRows[0].id)<0) {
								loadedTabs = [];
								loadedTabs.push(selectedRows[0].id);
								switch (tabid){
									case "tabB":							
										pageInTab.setTabItemSrc(tabid, "<%=path%>/product/splInfo/toSplFlowPage.do?splId="+selectedRows[0].id);
										break;
								}
							}
							SetIframe_height();
						}
				}
			}
		});
		$.extend(true, pageInApp, {
            pageInTab: pageInTab
        });
	};
</script>

<body class="iframeBody">
<div class="Wrapper">
<div id="pageInTab" class="pageInTab">
<div tabid="tabA" title="垫款单列表" lselected="true">
<div class="searchArea">
    <form id="searchBar">
        <div class="fieldset1 clearFix">
            <div class="fieldBox">
                <div class="label">垫款规则名称</div>
                <div class="field">
                    <input name="billNm" id="billNm" type="text" class="ui-textbox" value="">
                </div>
            </div>
			<div class="fieldBox">
				<div class="label">再融资项目名称</div>
				<div class="field">
					<input name="refPrjNm" id="refPrjNm" type="text" class="ui-textbox" value="">
				</div>
			</div>
			<div class="fieldBox">
                <div class="label">状态</div>
                <div class="field">
                    <select name="billStsCd" id="billStsCd" data-value=" ">
                    	<option value=" " seleted>请选择</option>
                       <c:forEach items="${billStsCdList}" var="kv">
						   <c:forEach items="${kv.value}" var="kv2">
								<option value="${kv2.key }">${kv2.value }</option>
						   </c:forEach>
                       </c:forEach>
                    </select>
                </div>
            </div>   
			<%--<div class="fieldBox">
                <div class="label">区域</div>
                <div class="field">
                    <div class="field">
                        <jsp:include page="../../system/sysRegion/region.jsp" flush="true" >
							<jsp:param name="regionShowLvl" value="2"/>
						</jsp:include>
                    </div>
                </div>
            </div>    --%>
            <div class="clearFix"></div>
			<div class="btnsBox formBtns notRight">
                <span id="searchBtn" class="sq-button-round">查询</span>
                <span id="clearBtn" class="sq-button-round">清空</span>
                <input id="resetBtn" type="reset" value="重置" class="l-button l-button-reset Hide"/>
            </div>
		</div>
	</form>
    </div>
<div id="ligergrid1" class="sq-grid"></div>
</div>
</div>
</div>
</body>
</html>